package cn.com.freelibra.forum.util;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

public class HtmlUtil {
	
	/**
	 * 获取纯文本
	 * @param htmlStr html内容
	 * @return 纯文本
	 */
	public static String removeHtmlInTag(String htmlStr) {
		  Document doc = Jsoup.parse(htmlStr);
		  String text = doc.text();
		  StringBuilder builder = new StringBuilder(text);
		  int index = 0;
		  while(builder.length()>index){
		    char tmp = builder.charAt(index);
		    if(Character.isSpaceChar(tmp) || Character.isWhitespace(tmp)){
		      builder.setCharAt(index, ' ');
		    }
		    index++;
		  }
		  text = builder.toString().replaceAll(" +", " ").trim();
		  return text;
	}

}
